Jiraiya Posted May 28, 2009 Share Posted May 28, 2009 I need help creating this php updating form its supposed to update a pic url with a new one that is submitted by a html form i what i have is shown below <form> Picture URL: <input type="text" pic="pic" /> <input type="submit" value="Submit" /> </form> <br /> </form> <?php $username = $_COOKIE['ID_my_site']; mysql_connect("mysql", "username", "password") or die(mysql_error()); mysql_select_db("members") or die(mysql_error()); $sql = mysql_query("UPDATE users SET `pic` = name") or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/159976-solved-php-text-form-update-help/ Share on other sites More sharing options...
Ken2k7 Posted May 28, 2009 Share Posted May 28, 2009 1. In your INPUT tag, what's pic="pic"? Did you mean name="pic"? 2. What's name in your SQL - UPDATE users SET `pic` = name? <form method="post"> Picture URL: <input type="text" name="pic" /> <input type="submit" name="submit" value="Submit" /> </form> <br /> </form> <?php if (isset($_POST['submit'])) { $username = $_COOKIE['ID_my_site']; mysql_connect("mysql", "username", "password") or die(mysql_error()); mysql_select_db("members") or die(mysql_error()); $pic = mysql_real_escape_string($_POST['pic']); $sql = mysql_query("UPDATE users SET `pic` = $pic WHERE username='$username'") or die(mysql_error()); } ? Link to comment https://forums.phpfreaks.com/topic/159976-solved-php-text-form-update-help/#findComment-843843 Share on other sites More sharing options...
Jiraiya Posted May 28, 2009 Author Share Posted May 28, 2009 1. yes i did mean name=pic 2. im trying to update the pic variable in my database with the text submitted in the form above Link to comment https://forums.phpfreaks.com/topic/159976-solved-php-text-form-update-help/#findComment-843846 Share on other sites More sharing options...
Jiraiya Posted May 28, 2009 Author Share Posted May 28, 2009 that code that you posted didnt do anything Link to comment https://forums.phpfreaks.com/topic/159976-solved-php-text-form-update-help/#findComment-843850 Share on other sites More sharing options...
Ken2k7 Posted May 28, 2009 Share Posted May 28, 2009 Well, I wasn't sure how to put it. If your SQL is just - $sql = mysql_query("UPDATE users SET `pic` = $pic") or die(mysql_error()); then that would modify the pic for all users! I'm sure you only want to update one right? Link to comment https://forums.phpfreaks.com/topic/159976-solved-php-text-form-update-help/#findComment-843858 Share on other sites More sharing options...
Jiraiya Posted May 28, 2009 Author Share Posted May 28, 2009 yes just for one user Link to comment https://forums.phpfreaks.com/topic/159976-solved-php-text-form-update-help/#findComment-843861 Share on other sites More sharing options...
Ken2k7 Posted May 28, 2009 Share Posted May 28, 2009 So how do you determine what user to set it for? What's the column name? Link to comment https://forums.phpfreaks.com/topic/159976-solved-php-text-form-update-help/#findComment-843863 Share on other sites More sharing options...
Jiraiya Posted May 28, 2009 Author Share Posted May 28, 2009 i was hoping this would do it $username = $_COOKIE['ID_my_site']; username = persons user name Link to comment https://forums.phpfreaks.com/topic/159976-solved-php-text-form-update-help/#findComment-843866 Share on other sites More sharing options...
Ken2k7 Posted May 28, 2009 Share Posted May 28, 2009 Hmm... <form method="post"> Picture URL: <input type="text" name="pic" /> <input type="submit" name="submit" value="Submit" /> </form> <br /> </form> <?php if (isset($_POST['submit'])) { $username = $_COOKIE['ID_my_site']; mysql_connect("mysql", "username", "password") or die(mysql_error()); mysql_select_db("members") or die(mysql_error()); $pic = mysql_real_escape_string($_POST['pic']); $username = mysql_real_escape_string($username); $sql = "UPDATE users SET `pic` = '$pic' WHERE username='$username'"; $result = mysql_query($sql) or die(mysql_error()); } Link to comment https://forums.phpfreaks.com/topic/159976-solved-php-text-form-update-help/#findComment-843869 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.