Jump to content

Can You Do This In Php?


TKW22

Recommended Posts

I would like to create a user control panel.I would like it to tell them what they had before and save what they put in. Like something like this .

user name: <input type="text" name="name">

And then under it or in it put what they had before.

your old user name: <p>what they had</p>

I tried to do it myself and I just get allot errors.

Link to comment
Share on other sites

Sure, you can do that. How are you saving the information? A database, like MySql? A file? A cookie? What other information are you saving?We can't make those decisions for you. Best would be to post what code you have so far, tell us where it breaks, and ask questions about the code. "Control panel" is too general a concept for us to give you a tried-and-true system.

Link to comment
Share on other sites

I'm using mysql.im new with both php and mysql.Heres the code i worked on.

<?phpsession_start();;require_once '....php';   $xbox = $_POST['xbo360'];        $ps3 = $_POST['ps4'];        $pc = $_POST['p6'];        $image = $_POST['c6image'];               $xbox = stripcslashes($xbox);$xbox = mysql_real_escape_string($xbox);$pc = stripcslashes($pc);$pc = mysql_real_escape_string($pc);$image = stripcslashes($image);$image = mysql_real_escape_string($image);$ps3 = stripcslashes($ps3);$ps3 = mysql_real_escape_string($ps3);         $result = mysql_query("SELECT cpimage, xb360, ps3, pc FROM users");       error_reporting(E_ALL);ini_set('html_errors', 1);ini_set('log_errors', 0);ini_set('display_errors', 1);?>

<?phpif (isset($_SESSION['user_name'])){?><div class="leftside"><form  method="POST"><img alt="" height="150" width="150" />image url:<input type="text" name="c6image"/><div class="reinput"><?php  echo $row['cpimage']; ?> </div></form></div><div class="rightside"><form  method="POST"><p>xbox360 tag: <input type="text" name="xbo360" value="" /></p><p>what you had<div class="reinput"><?php   echo $row['xb360'];?></div></p><p>ps3 tag: <input type="text" name="ps4" /></p><p>what you had<div class="reinput"><?php   echo $row['ps3']; ?></div></p><p>pc tag: <input type="text" name="p6"/></p><p>what you had<div class="reinput"><?php   {echo $row['pc']; ?></div></p></form></div><div class="center"><p>welcome</p><p>if your all done <form method="POST"><input type="submit" value="click here"/></form></p></div><?phpecho $xbox;  }}        else {echo 'sorry you must be login';}if (strlen(trim($xbox)) > 16 ){echo 'xbox360 tage to long';}elseif (strlen(trim($ps3)) > 16 ){echo 'ps3 tage to long';}elseif (strlen(trim($pc)) > 16 ){echo 'pc tage to long';}elseif (strlen(trim($image)) > 30 ){echo 'your image url is to long';}else {mysql_query("UPDATE users SET cpimage={$image}, xb360={$xbox}, ps3={$ps3}, pc={$pc} WHERE name='{$_SESSION['user_name']}'");            echo 'thanks your profile is updated <a href="http://domain.com">go back</a>';  }      ?>

Link to comment
Share on other sites

You've posted your code in 2 boxes, but I hope it's all part of the same file?To start, you have too many forms. Since your script uses ALL the input values, they all need to be submitted at once. So they should all be in ONE form, and the submit button should be part of that form also.You should also check the input values before you use them. Use isset() or empty() .If you want error reporting to work, use those functions at the top of your script.I see variables for $result and $row. I don't see code that uses $result to fetch a row. Did you not paste it, or do you not have any?

Link to comment
Share on other sites

they are both on the same script.if I add the code while or anything like that then i get something index.i had this code in there before.

while ($row = mysql_fetch_assoc($result))

and for the forums there split because of my layout .it goes like this

+-------------+ +--------------+ +--------------+| some code |  | some code  |  | some code  |+-------------+ +--------------+ +--------------+

how would you make that into one forum?Use isset() or empty() .that works fine till i put that while in there

Link to comment
Share on other sites

if I add the code while or anything like that then i get something index.
while ($row = mysql_fetch_assoc($result))

Show us what that code looks like in your script. If you want to get your SQL information, you have to use it. Show us what it looks like, and we can help you fix it.
how would you make that into one forum?
Put <form> before the first div and </form> after the last div. Those are the only form tags you need. Removing all the others shouldn't affect your layout, but if it does, worry about that later. You want the functions to work first. You can make the page look pretty after.
Link to comment
Share on other sites

update : got it to give me the info agin but still don't save the infook so something like this?

         <?php        $result = mysql_query("SELECT cpimage, xb360, ps3, pc FROM users");$row = mysql_fetch_array($result);if (isset($_SESSION['user_name'])){    while ($row = mysql_fetch_array($result)){?><div class="leftside"><form  method="POST"><img alt="" height="150" width="150" />image url:<input type="text" name="c6image"/><div class="reinput"><?php  echo $row['cpimage']; ?> </div></div><div class="rightside"><p>xbox360 tag: <input type="text" name="xbo360" value="" /></p><p>what you had<div class="reinput"><?php  echo $row['xb360'];?></div></p><p>ps3 tag: <input type="text" name="ps4" /></p><p>what you had<div class="reinput"><?php    echo $row['ps3']; ?></div></p><p>pc tag: <input type="text" name="p6"/></p><p>what you had<div class="reinput"><?php    echo $row['pc']; ?></div></p></div><div class="center"><p>welcome</p><p>if your all done <input type="submit" value="click here"/></form></p></div><?php}echo $xbox;  }        else {echo 'sorry you must be login';}if (strlen(trim($xbox)) > 16 ){echo 'xbox360 tage to long';}elseif (strlen(trim($ps3)) > 16 ){echo 'ps3 tage to long';}elseif (strlen(trim($pc)) > 16 ){echo 'pc tage to long';}elseif (strlen(trim($image)) > 30 ){echo 'your image url is to long';}else {mysql_query("UPDATE users SET cpimage={$image}, xb360={$xbox}, ps3={$ps3}, pc={$pc} WHERE name='{$_SESSION['user_name']}'");            echo 'thanks your profile is updated <a href="http://.....com">go back</a>';  }      ?>

by the way that don't work with the whileit comes up with ok... um now its not coming up with anything :) im not sure what i just did loledit: sorry didn't see i left the url

Link to comment
Share on other sites

I updated your code to make it more readable. Now that I understand it, I see that you're just printing info for one user, so you don't need the while loop. I did find a } where it didn't belong. Anyway, try this and see if anything gets better. Parts of the logic look wrong to me, but I don't think they'll produce errors.

<?php	$row = mysql_fetch_assoc($result);	if (isset($_SESSION['user_name'])) {?>		<form method="POST">			<div class="leftside">				<img alt="" height="150" width="150" />				image url:<input type="text" name="c6image"/>				<div class="reinput"><?php echo $row['cpimage']; ?> </div>			</div>			<div class="rightside">				<p>xbox360 tag: <input type="text" name="xbo360" value="" /></p>				<p>what you had<div class="reinput"><?php echo $row['xb360']; ?></div></p>				<p>ps3 tag: <input type="text" name="ps4" /></p>				<p>what you had<div class="reinput"><?php echo $row['ps3']; ?></div></p>				<p>pc tag: <input type="text" name="p6"/></p>				<p>what you had<div class="reinput"><?php echo $row['pc']; ?></div></p>			</div>			<div class="center"><p>welcome</p>				<p>if your all done	<input type="submit" value="click here"/></p>			</div>		</form><?php//		echo $xbox; I"M NOT SURE WHAT THIS IS DOING	} else {		echo 'sorry you must be login';	}	if (strlen(trim($xbox)) > 16 ) {		echo 'xbox360 tage to long';	} elseif (strlen(trim($ps3)) > 16 )	{		echo 'ps3 tage to long';	} elseif (strlen(trim($pc)) > 16 ) {		echo 'pc tage to long';	} elseif (strlen(trim($image)) > 30 ) {		echo 'your image url is to long';	} else {		$result = mysql_query("UPDATE users SET cpimage='$image', xb360='$xbox', ps3='$ps3', pc='$pc' WHERE name='{$_SESSION['user_name']}'");		echo $result; // TAKE OUT THIS LINE WHEN YOU'RE SURE THE QUERY IS WORKING -- it'll print 1 if things work, nothing if they don't		echo 'thanks your profile is updated <a href="http://.....com">go back</a>';	}?>

Link to comment
Share on other sites

Well, you can't just drop it in there. I gave you a piece. You should check it over, see if I made mistakes. Make sure it fits with what you have.You know, all this would be a lot easier if you forgot about the HTML for a while and just tried to echo your sql data. Make sure that logic works correctly. Then create a form with just ONE input. See if you can upload something and update your table with one thing.The more you try all at once, the more things there are to go wrong, and the more difficult it is to find them.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...