nathanmaxsonadil Posted July 29, 2007 Share Posted July 29, 2007 Is there a way to insert data to a mysql database trough a html link tag Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/ Share on other sites More sharing options...
Dragen Posted July 29, 2007 Share Posted July 29, 2007 yes. It would be the same theory as sql through a form. What's your sql query? Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310333 Share on other sites More sharing options...
nathanmaxsonadil Posted July 29, 2007 Author Share Posted July 29, 2007 INSERT INTO emailists (`stixy`) VALUES ('$username'); Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310341 Share on other sites More sharing options...
corbin Posted July 29, 2007 Share Posted July 29, 2007 With something like http://yousite.com/[email protected] you could do the following: page.php $email = $_GET['email']; mysql_connect('somehost', 'user', 'pass'); mysql_select_db('somedatabase'); mysql_query("INSERT INTO emailists (`stixy`) VALUES ('{$email}');") or die('Unable to insert the data'); Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310351 Share on other sites More sharing options...
nathanmaxsonadil Posted July 29, 2007 Author Share Posted July 29, 2007 the $email is when your logged in so it will not be displayed on the url bar Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310355 Share on other sites More sharing options...
Dragen Posted July 29, 2007 Share Posted July 29, 2007 you could try having the link something like: <a href="http://mydomain.com/mypage.php?insert=1 then: <?php if(isset($_GET['insert'] && $_GET['insert'] == '1'){ //sql query here } If the user is logged in you should be able to get their email address somehow.. is it stored in a session? Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310359 Share on other sites More sharing options...
nathanmaxsonadil Posted July 29, 2007 Author Share Posted July 29, 2007 yes I'm using this loginscript http://www.evolt.org/article/PHP_Login_System_with_Admin_Features/17/60384/index.html Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310362 Share on other sites More sharing options...
Dragen Posted July 29, 2007 Share Posted July 29, 2007 you're code should look something like this: <?php if(isset($_GET['insert'] && $_GET['insert'] == '1'){ $sql = "INSERT INTO `emailists` (`stixy`) VALUE ('" . $username . "')"; if($sqlres = mysql_query($sql)){ echo 'email address added'; }else{ echo mysql_error(); } } ?> with the link: <a href="http://mydomain.com/mypage.php?insert=1 Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310365 Share on other sites More sharing options...
nathanmaxsonadil Posted July 29, 2007 Author Share Posted July 29, 2007 my link is http://myurl.com/myurl.php Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310369 Share on other sites More sharing options...
Dragen Posted July 29, 2007 Share Posted July 29, 2007 just change the url to whatever page the if statement is on: <a href="http://myurl.com/myurl.php?insert=1"> Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310377 Share on other sites More sharing options...
nathanmaxsonadil Posted July 29, 2007 Author Share Posted July 29, 2007 I dont have the end ?insert=1 on the page Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310378 Share on other sites More sharing options...
nathanmaxsonadil Posted July 29, 2007 Author Share Posted July 29, 2007 bump Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310393 Share on other sites More sharing options...
Dragen Posted July 29, 2007 Share Posted July 29, 2007 no. the ?insert=1 part sets the $_GET['insert'] variable to 1. It's not part of the url. Just change the url of the link to whatever page you want the mysql query to be. Add ?insert=1 to the end of the url. Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310396 Share on other sites More sharing options...
nathanmaxsonadil Posted July 29, 2007 Author Share Posted July 29, 2007 It's giving me Parse error: syntax error, unexpected T_BOOLEAN_AND, expecting ',' or ')' in /home/nathan/public_html/stixy.php on line 20 Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310419 Share on other sites More sharing options...
trq Posted July 29, 2007 Share Posted July 29, 2007 Post your code. Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310429 Share on other sites More sharing options...
nathanmaxsonadil Posted July 30, 2007 Author Share Posted July 30, 2007 My code is <?php include 'header.php'; // Works. ?> <div id="content"> <div id="columnsC"><br/> <a href="http://www.stixy.com"><img style="border:0;" src="siteimg/stixy.jpg" alt="stixy"/></a><Br/> <p>Stixy helps users organize their world on flexible, shareable Web-based bulletin boards called Stixyboards. Unlike most personal productivity or project management software, Stixy doesn't dictate how users should organize their information. Users can create tasks, appointments, files, photos, notes, and bookmarks on their Stixyboards, organized in whatever way makes sense to them. Then they can share Stixyboards with friends, family, and colleagues.</p> </div> <div id="columnsD"> <? /** * User has already logged in, so display relavent links */ if($session->logged_in){ $dbh=mysql_connect ("localhost", "my_username", "my_pass") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("my_db"); echo "<ul>"; if(isset($_GET['insert'] && $_GET['insert'] == '1'){ $sql = "INSERT INTO `emailists` (`stixy`) VALUE ('" . $username . "')"; if($sqlres = mysql_query($sql)){ echo 'email address added'; }else{ echo mysql_error(); } } $sql = "SELECT stixy FROM emailists"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { echo "<li>"; echo $row['stixy'] . "</li>"; } } } echo "</ul>"; } else{ ?> <br/> <p style="border-style: solid; border-width: 3px;"><b>To Invite people or add yourself to the list you need to either login or if you dont have an account signup</b></p> <? } ?> </div> <?php include 'sidebar.php'; ?> <div style="clear: both;"> </div> </div> <?php include 'footer.php'; // Works. ?> Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310493 Share on other sites More sharing options...
Dragen Posted July 30, 2007 Share Posted July 30, 2007 change this part: if(isset($_GET['insert'] && $_GET['insert'] == '1'){ $sql = "INSERT INTO `emailists` (`stixy`) VALUE ('" . $username . "')"; if($sqlres = mysql_query($sql)){ echo 'email address added'; }else{ echo mysql_error(); } } to this: if(isset($_GET['insert']) && $_GET['insert'] == '1'){ $sql = "INSERT INTO `emailists` (`stixy`) VALUE ('" . $username . "')"; if($sqlres = mysql_query($sql)){ echo 'email address added'; }else{ echo mysql_error(); } } you had a missed out ) after the isset() Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310496 Share on other sites More sharing options...
nathanmaxsonadil Posted July 30, 2007 Author Share Posted July 30, 2007 thanks Link to comment https://forums.phpfreaks.com/topic/62361-solved-php-help/#findComment-310515 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.